from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.db import models
import settings


class University(models.Model):
    name = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200)
    hoodySizeGuideUrl = models.URLField(verbose_name="Link to Facebook note for hoody sizes")
    likeImage = models.FileField(upload_to='img/facebook/competition-picture/', null=True, blank=True, verbose_name="Image on likegate")
    entryImage = models.FileField(upload_to='img/facebook/competition-picture/', null=True, blank=True, verbose_name="Image on entry pages")
    closedImage = models.FileField(upload_to='img/facebook/competition-picture/', null=True, blank=True, verbose_name="Image on closed page")
    fullSizeLink = models.URLField(verbose_name="Link to full size image in Facebook Gallery")
    terms = models.URLField(verbose_name="Link to terms and conditions")
    closedPageTitle = models.CharField(max_length=200, verbose_name="Close Page Title")
    facebookPageUrl = models.URLField(verbose_name="Link to facebook page")
    facebookShareTitle = models.CharField(max_length=200, verbose_name="Share Title")
    facebookShareCaption = models.TextField(verbose_name="Share Caption")
    facebookShareDescription = models.TextField(verbose_name="Share Description")
    orderFromHere = models.URLField(verbose_name="Link for 'Order yours now'")
    objects = models.Manager()

    def __unicode__(self):
        return str(self.name)


class FacebookCompetition(models.Model):
    app_id = models.CharField(max_length=255, primary_key=True)
    app_secret = models.CharField(max_length=255, unique=True)
    opening_date = models.DateField()
    closing_date = models.DateField()
    university = models.ForeignKey(University,related_name='facebook_competition_competition')
    objects = models.Manager() #default

    def __unicode__(self):
        return 'Competition for ' + str(self.university) + ' Started: ' + str(self.opening_date)

SIZE_CHOICES = (
        (u'S', u'S'),
        (u'M', u'M'),
        (u'L', u'L'),
        (u'XL', u'XL'),
        (u'XXL', u'XXL'),
    )

class Entrant(models.Model):
    name = models.CharField(max_length=200)
    email = models.EmailField(max_length=200, primary_key=True)
    size = models.CharField(max_length=30, choices=SIZE_CHOICES, default='none', verbose_name='Select a size')
    university = models.ForeignKey(University, null=True)
    competition = models.ForeignKey(FacebookCompetition, null=True)

    def __unicode__(self):
        return str(self.name) +' ('+str(self.email)+')' + ' from ' + str(self.university)
